import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    user: {
      isLogin: !!localStorage.getItem('token'),
    },
  },
  getters: {
  },
  mutations: {
    setIsLogin(state, payload) {
      state.user.isLogin = payload;
    },
  },
  actions: {
    updateToken({ commit }) {
      const token = localStorage.getItem('token');
      if (!token) {
        commit('setIsLogin', false);
      }
    },
  },
  modules: {
  },
});
